package bigintegersum;

import java.util.ArrayList;
import java.util.List;


/**
 *
 * Author: Seabook
 *
 */
public class BigIntegerSum {

   public static void main(String[] args) {
	   BigIntegerSum bis = new BigIntegerSum();
       List<String> result = bis.calculateSum("456332135464441232245", "99865322145556477412");

       for (int i = result.size() - 1; i >= 0; i--) {
           System.out.print(result.get(i));
       }
   }

   public List<String> calculateSum(String integer1, String integer2) {
       List<String> result = new ArrayList<String>();

       int compareSize = integer1.length() - integer2.length();

       if (compareSize  > 0) {
           integer2 = add0s(integer2, Math.abs(compareSize));
       } else if(compareSize < 0) {
           integer1 = add0s(integer1, Math.abs(compareSize));

       }

       char[] integer1CharArr = integer1.toCharArray();
       char[] integer2CharArr = integer2.toCharArray();

       int i = integer1CharArr.length - 1;
       int needAdd = 0;
       while (i >= 0) {
           int temp = Character.getNumericValue(integer1CharArr[i])
                   + Character.getNumericValue((integer2CharArr[i]));
           temp += needAdd;
           if (temp >= 10) {
               needAdd = 1;
               temp -= 10;
           } else
               needAdd = 0;

           result.add(String.valueOf(temp));
           i --;
       }

       return result;
   }

   private String add0s(String org, int difference) {
       StringBuilder sb = new StringBuilder();
       for (int i = 0; i < difference; i++) {
           sb.append("0");
       }
       sb.append(org);

       return sb.toString();
   }
}
